package bairui.international.weixin.portal.miniapp.controller.user;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;
import com.lianjing.sh.wx.mp.miniapp.model.user.Model_PhoneEncryptedData;
import com.lianjing.sh.wx.mp.miniapp.tool.Util_WxAppPhoneInfo;

import bairui.international.model.domain.jpa.TB_User;
import bairui.international.service.Service_User;
import bairui.international.weixin.portal.miniapp.config.Config_Weixin_App;

/**
 *
 * 账户操作
 *
 * @generated
 * 
 * @see STest_C_User_Account_GainPhone 测试
 *
 */
@Controller
public class C_User_Account_GainPhone
 extends SC_User_Account_GainPhone 
{
	
	@Autowired private Config_Weixin_App config_Weixin_App;
	@Autowired private Service_User service_User;
	
	/**
	 * 获取手机号
	 */
	@Action(GainPhone.class)
	@PostMapping(GainPhone.RequestMappingValue)
	public @FomatOutput @ResponseBody Object gainPhone(
		ModelMap map, HttpServletRequest request,
		@Valid @RequestBody Util_WxAppPhoneInfo.GainPhoneInput input,
		@RequestParam String skey
	) throws Exception {
		TB_User user = service_User.findOne(it->it.skey.eq(skey));
		Model_PhoneEncryptedData phoneInfo = Util_WxAppPhoneInfo.gainPhoneInfo(config_Weixin_App, user.getSessionKey(), input);
		TB_User bean = service_User.edit(user.getId(), null, phoneInfo.getPhoneNumber(), null, null, null);
		return new C_User_Account_Get.Output(bean);
	}
	

}
